/*
 * Design by  free.wang <freefis@gmail.com>
 * Licence unser BSD  lisence
 * Complete on May 30 21:30 , 2009 
 *
 * Environment:
 *     GCC 4.3.2
 *     Ubuntu / Linux i386
 *     Mac OS X / FreeBSD 4.x
 */

/*
 *  Main code will call  
 * 	  all_cost( double prodset[6], double workers[6], double extras[6] )
 * to calculate the Result.
*/


#include "calculate.h"

double STDPRODSET[6] = {1000,1100,1150,1300,1400,1300};



double _cost_by_make( double prod, double worker, double extra)
{
    double _cost_by_worker = (18*extra + 8*12) * worker;
    double _cost_by_proxy  = (prod - (worker*18+extra)/1.6) * 200;
    return _cost_by_worker + _cost_by_proxy;
}

/* 库存及存货成本 */
double _more_or_less( double stdprod, double prod)
{
    if(prod>stdprod)
       return (prod-stdprod)*10;
    else
       return (stdprod-prod)*20;
}

/* 培训及解聘成本 */
double _fire_or_train( double workers[6]){
    int i , _cost_by_train , _cost_by_fire =0;
    double max = workers[0];
    for(i=0;i<6;i++){
        /* 最大员工数 */
        if(workers[i]>max) { 
            max=workers[i]; 
        }
        /* 邻月解聘人数 */
        if ( (i>1) && (workers[i-1]>workers[i]) ) {
            _cost_by_fire += (workers[i-1] - workers[i]) * 100;
        }
            
    }
    _cost_by_train = max * 50;
    return _cost_by_fire + _cost_by_train;
}

/* 每月成本 */
double _all_month_cost( double stdprod, double prod, double worker, double extra)
{
    double a = _cost_by_make(prod,worker,extra); 
    double b = _more_or_less(stdprod,prod);
    return a+b;
}



/* 最终成本  */
double all_cost( double seed[3][6] ){
/*
	seed[0] -> double prodset[6]
	seed[1] -> double workers[6]
    seed[2] -> double extras[6]
*/
    int i;
    double _all_cost = 0 ;
    for(i=0;i<6;i++)
        _all_cost += _all_month_cost( STDPRODSET[i] , seed[0][i] , seed[1][i] , seed[2][i] );
    return _all_cost + _fire_or_train(seed[1]);
}
